package com.whmskj.xjlhsc.mobie.equipmentManage.service.imp;

import cn.hutool.core.collection.CollectionUtil;
import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhsc.mapper.MachineComparisonMapper;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.DeviceEnergyAndYieldVo;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.MachineComparisonVO;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.ProductionCapacityVo;
import com.whmskj.xjlhsc.mobie.equipmentManage.service.IMachineComparisonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author jiaruchun
 * @date 2025-09-01 14:49
 */
@Service
public class MachineComparisonServiceImpl implements IMachineComparisonService {
    @Autowired
    private MachineComparisonMapper machineComparisonMapper;

    @Override
    public  List<ProductionCapacityVo> machineComparison(Integer mesId, Integer mesId2, LocalDate start, LocalDate end) {

//        Map<String,Object> resultMap=new HashMap<>();

        Page.startPage();
        List<ProductionCapacityVo> productionCapacityVos = machineComparisonMapper.machineComparison(mesId,mesId2,start, end);
//        resultMap.put("list",productionCapacityVos);

//        List<DeviceEnergyAndYieldVo> deviceEnergyAndYield=new ArrayList<>();

//          deviceEnergyAndYield =  machineComparisonMapper.selectDeviceEnergyAndYield(mesId,mesId2,start,end);

//        resultMap.put("deviceEnergyAndYield",deviceEnergyAndYield);


//        Map<Integer, List<ProductionCapacityVo>> collect = productionCapacityVos.stream().collect(Collectors.groupingBy(ProductionCapacityVo::getMesid));
//        Set<Integer> keys = collect.keySet();
//        for (Integer key : keys) {
//            Map<String,Object> map=new HashMap<>();
//            List<ProductionCapacityVo> productionCapacityVos1 = collect.get(key);
//            map.put("platform",productionCapacityVos1.get(0).getPlatForm());
//
//            double sumYield=0.0;
//            double sumEnergy=0.0;
//            for (ProductionCapacityVo productionCapacityVo : productionCapacityVos1) {
//                sumYield+=productionCapacityVo.getActualyieldkg();
//                sumEnergy+=productionCapacityVo.getEnergy();
//            }
//            map.put("deviceSumYield",sumYield);
//            map.put("deviceSumEnergy",sumEnergy);
//            map.put("list",productionCapacityVos1);
//            list.add(map);
//        }
        return productionCapacityVos;
    }
}
